{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sisl\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "First Siesta example for analysing output.\n",
    "\n",
    "This example will calculate the electronic structure of graphene using Siesta, and we will post-process the data to calculate band-structures etc.\n",
    "\n",
    "We remark that settings during the Siesta/TranSiesta tutorials are not necessarily converged or proper settings. Users need to invest time in understanding the intrinsics of Siesta before performing real calculations!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exercises\n",
    "\n",
    "As this is your first example of running Siesta, there are a few things you should know:\n",
    "\n",
    "1. Start by calculating the electronic structure using Siesta\n",
    "\n",
    "       siesta RUN.fdf > RUN.out\n",
    "\n",
    "  - Go through the output of Siesta to get used to it, also to assert that it ran without errors (always do this!) ((always, **always** do THIS!))\n",
    "  - Ensure that the self-consistent field (SCF) has indeed converged, Siesta will, by default, die if it hasn't converged the SCF.\n",
    "  \n",
    "2. Use `sisl` to read-in the electronic structure (the Hamiltonian). There are several ways of doing this, for now you should try these two methods:\n",
    "\n",
    "         H_fdf = sisl.Hamiltonian.read('RUN.fdf')\n",
    "         H_TSHS = sisl.Hamiltonian.read('siesta.TSHS')\n",
    "         \n",
    "    Print the objects and note the difference between the two objects.\n",
    "    What do you think these differences mean? (it isn't relevant for this tutorial, but it will be in later tutorials).\n",
    "    \n",
    "3. Calculate the $\\Gamma$-point eigen-spectrum using both above Hamiltonians (search the `sisl` documentation for `eigh`). Are they different? If so, why, if not, why not?\n",
    "\n",
    "4. Calculate the band-structure using the DFT electronic structure using `sisl`. Also calculate the band-structure using the tight-binding Hamiltonian ([TB 1](../TB_01/run.ipynb)) and compare the two.  \n",
    "*HINT*: Zoom in on an energy-range from $-3$ eV to $3$ eV and plot both the DFT bands and the TB bands in the same plot.  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Read Hamiltonians using two different methods"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Calculate eigenspectrum at the \\Gamma-point\n",
    "eig_fdf = H_fdf.<>\n",
    "eig_TSHS = H_TSHS.<>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Calculate band-structure from DFT Hamiltonian and TB Hamiltonian\n",
    "band = sisl.BandStructure(sisl.geom.graphene(), <fill-in correct points and labels>)\n",
    "xtick, xtick_label = band.lineartick()\n",
    "lk = band.lineark()\n",
    "\n",
    "ax = plt.gca()\n",
    "ax.xaxis.set_ticks(xtick)\n",
    "ax.set_xticklabels(xtick_label)\n",
    "\n",
    "# Define limits of the y-axis (Energy!)\n",
    "# Play with this if you want! :)\n",
    "ax.set_ylim(-3, 3)\n",
    "ax.set_ylabel('Eigenspectrum [eV]')\n",
    "\n",
    "# Plot x-major lines at the ticks\n",
    "ymin, ymax = ax.get_ylim()\n",
    "for tick in xtick:\n",
    "    ax.plot([tick,tick], [ymin, ymax], 'k')\n",
    "\n",
    "# Plot band-structures\n",
    "band.set_parent(<DFT Hamiltonian>)\n",
    "eigs = band.apply.ndarray.eigh()\n",
    "ax.plot(lk, eigs)\n",
    "    \n",
    "# You need to create the TB Hamiltonian, see e.g. TB_01\n",
    "band.set_parent(<TB Hamiltonian>)\n",
    "eigs = band.apply.ndarray.eigh()\n",
    "ax.plot(lk, eigs, '--')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
